import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore(
  'counter',
  () => {
    //持久化存储count
    const count = ref(0)
    const doubleCount = computed(() => count.value * 2)
    function increment() {
      count.value++
    }
    function decrement() {
      count.value--
    }

    const name = ref('pinia')
    function changeName(newName: string) {
      name.value = newName
    }
    return { count, doubleCount, increment, decrement, name, changeName }
  },
  {
    persist: {
      paths: ['count'],
      // 添加更多调试选项
      key: 'store-counter',
      storage: localStorage,
    },
  },
)
